跳到主要内容

Fortran 数组赋初值

integer :: a(5) = [1,2,3,4,5]
integer :: a(5) = 5
! 隐循环的常规形式:(arg1(i), arg2(i), ..., i = start, end, incr)
integer a(5) = [1, (2, i = 2, 4), 5]
integer a(5) = [(i, i = 1, 5)]
integer a(25) = [((0, i = 1, 4), 5*j, j = 1, 5)]
integer a(2,2) = (/1, 2, 3, 4/) ! 按列,a(2,1)=2
write(*, *) (a(i), i=2, 4)
write(*, *) (a(i), i=2, 10, 2)
write(*, *) ((r, c, c=1, 2), r=1, 2)